package com.cqjtu.eecs.utils;

import com.cqjtu.eecs.entity.*;
import com.cqjtu.eecs.entity.dto.TeacherDto;
import com.cqjtu.eecs.entity.dto.TeacherDto2;
import com.cqjtu.eecs.mapper.AcademyMapper;
import com.cqjtu.eecs.mapper.MajorMapper;
import com.cqjtu.eecs.service.*;
import com.cqjtu.eecs.service.impl.MajorServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class MapUtils {
    @Autowired
    private IMajorService iMajorService;
    @Autowired
    private INaturalClassService iNaturalClassService;
    @Autowired
    private ICourseSystemService iCourseSystemService;
    @Autowired
    private IAcademyService iAcademyService;
    @Autowired
    private ITeacherService iTeacherService;
    public  Map<String,String> getMapMajorUtil(){
        List<Major> list = iMajorService.list();
        Map<String,String> mapMajor=new HashMap<>();
        for (int i=0;i<list.size();i++){
            mapMajor.put(list.get(i).getMajorCode(),list.get(i).getMajorName());
        }
        return mapMajor;
    }
    public  Map<Integer,String> getNaturalClassUtil(){
        List<NaturalClass> list = iNaturalClassService.list();
        Map<Integer,String> map=new HashMap<>();
        for (int i=0;i<list.size();i++){
            map.put(list.get(i).getNcId(),list.get(i).getNaturalClassName());
        }
        return map;
    }
    public Map<Integer,String> getCourseSystemUtil(){
        List<CourseSystem> list = iCourseSystemService.list();
        Map<Integer,String> map=new HashMap<>();
        for (int i=0;i<list.size();i++){
            map.put(list.get(i).getCourseSystemId(),list.get(i).getCourseSystemName());
        }
        return map;
    }
    public Map<String,String> getMajorCodeAcademyNameUtil(){
        List<Major> majors = iMajorService.list();
        List<Academy> academies = iAcademyService.list();
        Map<String,String> map01=new HashMap<>();
        Map<String,String> map02=new HashMap<>();
        for (int i=0;i<academies.size();i++){
            map01.put(academies.get(i).getAcademyId(),academies.get(i).getAcademyName());
        }
        for (int i=0;i<majors.size();i++){
            String majorCode = majors.get(i).getMajorCode();
            String academyId = majors.get(i).getAcademyId();
            map02.put(majorCode,map01.get(academyId));
        }
        return map02;
    }
    public Map<Integer, TeacherDto2> getTeacherUtil(){
        List<Teacher> list = iTeacherService.list();
        Map<Integer,TeacherDto2> map=new HashMap<>();
        for (int i=0;i<list.size();i++){
            map.put(list.get(i).getTid(),new TeacherDto2(list.get(i).getTeacherName(),list.get(i).getTeacherCode()));
        }
        return map;
    }
}
